layui.use(['element','layer'], function() {
    //动态菜单
    var layer=layui.layer;
    function indexLoad(){
        layui.jquery.ajax({
            url: "/group/list",
            method: 'POST',
            success: function(res) {
                var html = "";
                if (res!=""){
                    for(var i = 0; i < res.length; i++) {
                        var strli ="";
                        strli+="<dd><a ondragstart=\"return false\" id=\"group_"+res[i].id+"\" href=\"/user/toIndex?id=2,"+res[i].id +"\" target=\"right_view\">"+res[i].groupName+"</a></dd>";
                        html = html + strli;
                    }
                }else {
                    html+="<dd><a>暂无好友</a></dd>";
                }
                layui.jquery("#groups").html(html);
                layui.element.init(); //一定初始化一次
            }
        });
        //动态菜单
        layui.jquery.ajax({
            url: "/user/list",
            method: 'POST',
            success: function(res) {
                var html = "";
                if (res!=""){
                    for(var i = 0; i < res.length; i++) {
                        var strli ="";
                        strli+="<dd><a ondragstart=\"return false\" id=\"friend_"+res[i].id+"\" href=\"/user/toIndex?id=1,"+res[i].id +"\"target=\"right_view\">"+res[i].userName+"</a></dd>";
                        html = html + strli;
                    }
                }else {
                    html+="<dd><a>暂无好友</a></dd>";
                }
                layui.jquery("#friends").html(html);
                layui.element.init(); //一定初始化一次
            }
        });
    };
    window.setInterval(indexLoad, 500);
    $("#addFriend").click(function () {
        layer.open({
            title : "添加好友",
            type : 2,
            area: ["700px", "520px"],
            content : "/friend/toAdd",
            end: function () { //最后执行reload
                window.location.reload();
            }
        })
    });
    $("#addMessage").click(function () {
        layer.open({
            title : "好友申请",
            type : 2,
            area: ["700px", "520px"],
            content : "/friend/toMessage",
            end: function () { //最后执行reload
                window.location.reload();
            }
        })
    });
    $("#addGroup").click(function () {
        layer.open({
            title : "创建群聊",
            type : 2,
            area: ["700px", "520px"],
            content : "/group/toAdd",
            end: function () { //最后执行reload
                window.location.reload();
            }
        })
    });
});